package com.rj.ability.leqi.common;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.rj.core.algorithm.AlgorithmUtils;
import com.rj.util.ByteUtils;
import com.rj.util.JsonUtil;
import lombok.Data;

@Data
public class Response<T extends BizSuccessCommonRes> {
    /**
     * "16 位随机数字和字母组合
     */
    @JsonProperty("RequestId")
    private String requestId;
    /**
     * 返回数据
     */
    @JsonProperty("Data")
    private String data;

    @JsonProperty("Error")
    private BizFailRes error;

    public T decryptData(String key, TypeReference<T> typeReference) {
        String decryptData = AlgorithmUtils.Sm.sm4(ByteUtils.getBytes(key)).decryptStr(data);
        T res = JsonUtil.toObject(decryptData, typeReference);
        return res;
    }
}
